#include <iterator>
#include <vector>
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    string LCS(string str1, string str2) {
        int m = str1.size();
        int n = str2.size();
        int endpos = 0;
        int maxlen = 0;
        vector<vector<int>> dp(m + 1, vector<int>(n + 1));
        for (int i = 1; i < m + 1; i++)
        {
            for (int j = 1; j < n + 1; j++)
            {
                if (str1[i - 1] == str2[j - 1])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = 0;
                if (dp[i][j] > maxlen)
                {
                    maxlen = dp[i][j];
                    endpos = i;
                }
            }
        }
        return str1.substr(endpos - maxlen, maxlen);
    }
};


int main()
{
    Solution s;
    string str1 = "1AB2345CD";
    string str2 = "12345EF";
    s.LCS(str1,str2);
    return 0;
}